package com.thread.test;

/**
 * @author huang
 * @version 0.0.1
 * @apiNote TODO
 * @since 2021/2/22 11:42
 **/
public class WaitNotifyInterrupt {

    static Object object = new Object();

    public static void main(String[] args) {
        Thread threadA = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("--begin--");
                    //阻塞当前线程
                    synchronized (object) {
                        object.wait();
                    }
                    System.out.println("--end--");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        threadA.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("--begin interrupt threadA--");
        //threadA调用共享对象的wait()方法被阻塞挂起后，主线程中断了threadA线程导致抛出了InterruptedException异常
        threadA.interrupt();
        System.out.println("--end interrupt threadA--");
    }

}
